package org.sippr.service.impl;

import org.sippr.mapper.SdLorraMapper;
import org.sippr.pojo.SdLorra;
import org.sippr.service.SdLorraService;
import org.sippr.utils.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Service
public class SdLorraImpl implements SdLorraService {
    @Autowired
    private SdLorraMapper sdLorraMapper;

    @Override
    public SdLorra findByAlias(String alias) {
        return sdLorraMapper.findByAlias(alias);
    }

    @Override
    public SdLorra findByName(String name) {
        return sdLorraMapper.findByName(name);
    }

    @Override
    public void update(SdLorra value) {
        Map<String, Object> map = ThreadLocalUtil.get();
        String id = (String) map.get("id");

        value.setUpdateUser(id);

        //记录时间
        LocalDateTime time = LocalDateTime.now();
        value.setUpdateTime(time);

        sdLorraMapper.updateByPrimaryKey(value);

    }

    @Override
    public void add(SdLorra value) {
        Map<String, Object> map = ThreadLocalUtil.get();
        String id = (String) map.get("id");

        value.setUpdateUser(id);
        value.setCreateUser(id);

        //记录时间
        LocalDateTime time = LocalDateTime.now();
        value.setCreateTime(time);
        value.setUpdateTime(time);
        sdLorraMapper.insert(value);
    }

    @Override
    public List<SdLorra> list() {
        return sdLorraMapper.list();
    }

    @Override
    public void delete(Integer id) {
        sdLorraMapper.deleteByPrimaryKey(id);
    }

    @Override
    public SdLorra get(Integer lorraId) {
        return sdLorraMapper.selectByPrimaryKey(lorraId);
    }
}
